<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" >

<title>linux常用命令 | After Learning</title>
<meta name="description" content="温故而知新">

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="shortcut icon" href="http://www.zydone.xyz/favicon.ico?v=1571108508898">

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/papercss@1.6.1/dist/paper.min.css" />
<link rel="stylesheet" href="http://www.zydone.xyz/styles/main.css">


  
    <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css" />
  

  

<script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>


<link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />


  </head>
  <body>
  
    <nav class="navbar border fixed split-nav">
  <div class="nav-brand">
    <h3><a href="http://www.zydone.xyz">After Learning</a></h3>
  </div>
  <div class="collapsible">
    <input id="collapsible1" type="checkbox" name="collapsible1">
    <button>
      <label for="collapsible1">
        <div class="bar1"></div>
        <div class="bar2"></div>
        <div class="bar3"></div>
      </label>
    </button>
    <div class="collapsible-body">
      <ul class="inline">
        
          <li>
            
              <a href="/" class="menu">
                首页
              </a>
            
          </li>
        
          <li>
            
              <a href="/archives" class="menu">
                归档
              </a>
            
          </li>
        
          <li>
            
              <a href="/tags" class="menu">
                标签
              </a>
            
          </li>
        
          <li>
            
              <a href="/post/about" class="menu">
                关于
              </a>
            
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div id="top" class="row site">
      <div class="sm-12 md-8 col">
        <div class="paper">
          <article class="article">
            <h1>linux常用命令</h1>
            <p class="article-meta">
              2019-04-18
              
                <a href="http://www.zydone.xyz/tag/GEcvnyWUF" class="badge ">
                  linux
                </a>
              
            </p>
            
            <div class="post-content">
              <h1 id="grep">grep</h1>
<ul>
<li>grep forest f.txt     #文件查找</li>
<li>grep forest f.txt cpf.txt #多文件查找</li>
<li>grep 'log' /home/admin -r -n #目录下查找所有符合关键字的文件</li>
<li>cat f.txt | grep -i shopbase</li>
<li>grep 'shopbase' /home/admin -r -n --include *.{vm,java} #指定文件后缀</li>
<li>grep 'shopbase' /home/admin -r -n --exclude *.{vm,java} #反匹配</li>
<li>seq 10 | grep 5 -A 3    #上匹配</li>
<li>seq 10 | grep 5 -B 3    #下匹配</li>
<li>seq 10 | grep 5 -C 3    #上下匹配，平时用这个就妥了</li>
<li>cat f.txt | grep -c 'SHOPBASE'</li>
</ul>
<h1 id="find">find</h1>
<ul>
<li>sudo -u admin find /home/admin /tmp /usr -name *.log(多个目录去找)</li>
<li>find . -iname *.txt(大小写都匹配)</li>
<li>find . -type d(当前目录下的所有子目录)</li>
<li>find /usr -type l(当前目录下所有的符号链接)</li>
<li>find /usr -type l -name &quot;z*&quot; -ls(符号链接的详细信息 eg:inode,目录)</li>
<li>find /home/admin -size +250000k(超过250000k的文件，当然+改成-就是小于了)</li>
<li>find /home/admin f -perm 777 -exec ls -l {} ; (按照权限查询文件)</li>
<li>find /home/admin -atime -1  1天内访问过的文件</li>
<li>find /home/admin -ctime -1  1天内状态改变过的文件</li>
<li>find /home/admin -mtime -1  1天内修改过的文件</li>
<li>find /home/admin -amin -1  1分钟内访问过的文件</li>
<li>find /home/admin -cmin -1  1分钟内状态改变过的文件</li>
<li>find /home/admin -mmin -1  1分钟内修改过的文件</li>
<li>find / -type f -name &quot;*.log&quot; | xargs grep &quot;ERROR&quot;  从根目录开始查找所有扩展名为.log的文本文件，并找出包含”ERROR”的行</li>
</ul>
<h1 id="查看-当前连接">查看 当前连接</h1>
<p>netstat -nat|awk  '{print $6}'|sort|uniq -c|sort -rn</p>
<p><strong>查看tcp连接数</strong><br>
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'</p>
<h1 id="tcpdump-抓包">tcpdump 抓包</h1>
<p>截获主机 <em>.</em>.<em>.<em>和主机</em>.</em>.<em>.</em> 或*.<em>.</em>.<em>的通信<br>
tcpdump host <em>.</em>.</em>.* and \ (<em>.</em>.<em>.</em> or <em>.</em>.<em>.</em> )</p>
<p>tcpdump -i  any host  <em>.</em>.<em>.</em>   -s0 -w t1.cap</p>
<p>-i eth1 : 只抓经过接口eth1的包<br>
-s 0 : 抓取数据包时默认抓取长度为68字节。加上-S 0 后可以抓到完整的数据包</p>
<p>-w t1.cap : 保存成cap文件，方便用ethereal(即wireshark)分析</p>
<h1 id="不挂起运行jar包">不挂起运行jar包</h1>
<p>nohup java -jar *.jar &gt;temp.txt &amp;</p>

            </div>
          </article>
        </div>
        <div class="paper" data-aos="fade-in">
          
        </div>
        
          
            <div class="paper" data-aos="fade-in">
              <div id="gitalk-container"></div>
            </div>
          

          
        
      </div>

      <div class="sm-12 md-4 col sidebar">
  <div class="paper info-container">
    <img src="http://www.zydone.xyz/images/avatar.png?v=1571108508898" class="no-responsive avatar">
    <div class="text-muted">温故而知新</div>
    <div class="social-container">
      
        
          <a href="https://github.com/yida-zhang/after-learning.github.io" target="_blank">
            <i class="fab fa-github"></i>
          </a>
        
      
        
      
        
      
        
      
        
      
    </div>
  </div>
  <div class="paper">
    <div class="sidebar-title">
      最新文章
    </div>
    <div class="row">
      <ul>
        
          
            <li>
              <a href="http://www.zydone.xyz/post/git-shan-chu-fen-zhi">git删除分支</a>
            </li>
          
        
          
            <li>
              <a href="http://www.zydone.xyz/post/git-xiu-gai-fen-zhi-ming-cheng">git修改分支名称</a>
            </li>
          
        
          
            <li>
              <a href="http://www.zydone.xyz/post/git-cong-master-la-qu-fen-zhi">git从master拉取分支</a>
            </li>
          
        
          
            <li>
              <a href="http://www.zydone.xyz/post/git-he-bing-qi-ta-fen-zhi-dai-ma-dao-master">git合并其他分支代码到master</a>
            </li>
          
        
          
            <li>
              <a href="http://www.zydone.xyz/post/linux-chang-yong-ming-ling">linux常用命令</a>
            </li>
          
        
      </ul>
    </div>
  </div>
  <div class="paper">
    <div class="sidebar-title">
      标签列表
    </div>
    <div class="row">
      
        <a href="http://www.zydone.xyz/tag/knzWI3FT-" class="badge warning">
          git
        </a>
      
        <a href="http://www.zydone.xyz/tag/GEcvnyWUF" class="badge secondary">
          linux
        </a>
      
    </div>
  </div>
  <div class="paper">
    Powered by <a href="https://github.com/yida-zhang/after-learning.github.io" target="_blank">After Learning</a>
  </div>
</div>


    </div>

    <script src="https://unpkg.com/aos@next/dist/aos.js"></script>

<script type="application/javascript">

AOS.init();

hljs.initHighlightingOnLoad()

</script>


  
  
    <script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
    <script>

      var gitalk = new Gitalk({
        clientID: '78af740def51eebd6b69',
        clientSecret: '81410d1d98cf274e622fb4992049608e50f3db88',
        repo: 'after-learning.github.io',
        owner: 'yida-zhang',
        admin: ['yida-zhang'],
        id: location.pathname,      // Ensure uniqueness and length less than 50
        distractionFreeMode: false  // Facebook-like distraction free mode
      })

      gitalk.render('gitalk-container')

    </script>
  

  




  </body>
</html>
